﻿using System;
using System.Collections.Generic;
using System.Globalization;


namespace FireBus.Shell.ExtensionManager
{
	public class UnloadCommand : ICommand
	{
		private readonly Extension _Extension;


		public UnloadCommand(Extension extension)
		{
			if (extension == null)
			{
				throw new ArgumentNullException("extension");
			}
			_Extension = extension;
		}


		public String Name
		{
			get { return "unload"; }
		}

		public String Description
		{
			get
			{
				return
					@"Unloads extension by given name.
Example:
unload ExtensionManager";
			}
		}

		public String Execute(IList<String> args)
		{
			if (args == null)
			{
				throw new ArgumentNullException("args");
			}
			if (args.Count < 1)
			{
				return "Invalid arguments";
			}
			var extensionName = args[0];

			_Extension.UnloadExtension(extensionName);

			return
				String.Format(
					CultureInfo.InvariantCulture,
					"Extension {0} was marked for unload",
					extensionName);
		}
	}
}
